package com.zx._12_算法.左程云算法练习;

/**
 * sum = 1! + 2! + 3! + ... + n!
 * sum   1  + 2  + 6  + 24 ;
 */
public class Case_02 {

    public static void main(String[] args) {
        System.out.println(fun(1));
        System.out.println(fun(2));
        System.out.println(fun(3));
        System.out.println(fun(4));

    }

    public static int fun(int n) {
        int sum = 0;

        // 上个阶乘的结果
        int last = 1;

        for (int i = 1; i <= n; i++) {
            int cur = last * i;
            sum += cur;
            last = cur;
        }

        return sum;
    }
}
